download

Handling Email Attachments with Power Automate: A Comprehensive Guide

2 Comments

Overview of Power Automate

Microsoft offers Power Automate, formerly known as Microsoft Flow, a service that lets users set up automatic processes between different apps and services to synchronize files, receive alerts, gather statistics, and more. It is a component of the Microsoft Power Platform.

With Power Automate, users can improve productivity, integrate multiple systems, and optimize operations without needing to know a lot about programming. It is an effective solution for both straightforward and sophisticated automation requirements due to its versatility and extensive variety of integrations.

Key Capabilities of Power Automate

Automate Routine processes: To save time and minimize errors, automate repetitive processes such as data entry and file synchronization by creating workflows.

Approval Workflows: To guarantee compliance and appropriate oversight, set up workflows that call for approval, such document review procedures.

Integration with Several Services: Connect to more than 300 services and applications, such as Dropbox, Google services, Office 365, Dynamics 365, Azure, SharePoint, OneDrive, and SQL Server.

Event-Driven Automation: Using triggers to begin workflows in response to events—like getting an email, adding a new file, or updating a record.

Multiple Actions: Specify a sequence of actions, such task creation, database updates, notice sending, and more, that happen after the trigger.

Flow Analytics: Track the effectiveness and utilization of your workflows with the help of built-in analytics.

Logging and Diagnostics: To troubleshoot and optimize workflows, access comprehensive logs and diagnostic data.

Role-Based Workflows: Assign tasks and workflows to designated roles within the company to make sure the appropriate individuals are taking the appropriate actions.

Audit and Compliance: To support compliance and regulatory needs, keep an audit record of process activities.

AI Builder: Without requiring deep coding skills, integrate AI features like object detection, form processing, and prediction models into workflows.

Sample Use Case

I’ll walk over a use case in this post that I utilized to automate a routine task for my team.  The team periodically got random requests from customers via email, such as hash generation. Following processing, the hash team must respond via the same email. I automated the email section through Power-Automate and the hash generation through a Python script. You may like the blog post on ‘pytest’ https://dasfascination.com/10-fantastic-pytest-features/

Automation flow for the above use case:

  • The power automation flow will trigger when a mail received with one attachment (an excel file with CDSNs) and with a substring, “HASH_Generation” , in the Subject Line.
  • Then the flow will verify the domain name with an or condition like @gmail.com or @yahoo.tv
  • If the above condition satisfies the flow will download the attachment to a remote or local system (input folder).
  • Then the flow will wait for 2 minutes for the output file (a file with CDSNs and corresponding Hash).
  • A python script will be scheduled in the remote/local system from task scheduler which continuously monitor the input folder for excel files.
  • When a excel file arrives the python script generate hash and save the attachment to output folder.
  • The power-automate will check the output file after 2-minute delay and share a reply to all with the hash generated excel file

In this article, I will explain how to send and receive emails with attachments using Power Automate.

Getting Started with Power Automate

Precondition: A Microsoft 365 Account either Work or School Account or personal account. The service availability with personal account is limited.

Login: First, login to your Microsoft office account (office.com). If you are not able to find power-automate app in your account, select ‘App Launcher’ (the icon in the left top of the site) and you will find Power-Automate there. On clicking the icon, you will redirected to https://make.powerautomate.com/ page.

Picture1

Automate the flow for receiving and sending emails with attachments in one drive folder.

  • Click on ‘ + Create’ icon, then ‘Automate Cloud Flow.
Power Automate
  • Give the name of the flow and the search trigger for email arrival. Choose the V3 option if you have a work account.
Picture3 1
  • Set the parameter value for the email arrival trigger. In the above sample case, the subject should contain the “Hash_Generation” string, and the mail should have an attachment.
Picture4 1
  • Now click on the icon and search for condition. Next, add it to your flow to check the domain name in the from field of the email.
Picture5 1
  • Now if the condition is true, search action ‘Apply to each’ to save attachments. Save attachments in the parameter.
Picture6 1
  • Now save the attachment in your one-drive folder with the create file action.
Picture7 1
  • In the Create file action, give the folder and file name as per your choice, and the file content is the attachment content from the above steps. If you click on the File Content box, you get two options: ‘Insert data from your previous step” and ‘Insert expresession’. Click on insert expresession and ‘Dynamcic content’ section. Search content. Select ‘Attachment Content.
Picture8 1
Picture9 1
  • Now you must wait for some time for the processing of the input file and the creation of the hash output file by the Python script. That can be achieved by adding some delay or adding a trigger, like when a file is created in the output folder.
Picture10
  • Now get the file content to attach to the email.
Picture11
  • Last, send a reply above the mail with the content of the file as an attachment. Choose the message ID to send a reply to the same email. Write a message and attach the file content.
Picture12

Automate the flow for receive send email with attachment on remote system.

In this case the flow is same as above, but all the action needs to choose from file system rather that Onedrive for business.  User also need to create a connection to the remote system by power automate using On-Premises Data Gateway. This connection needs to use in all the flows.

The on-premises gateway allows cloud-based services like Power Automate to securely connect and interact with data and resources that are located on your local network. Here’s a general guide on how to create an on-premises gateway.

Installation:

  • Download the standard mode Gateway from below link which is used for office/school network.https://learn.microsoft.com/en-us/data-integration/gateway/service-gateway-install
  • Follow the requirements section on the above link for remote system.
  • Run the installer: Keep the default installation path, accept the terms of use, and click Install.
  • Sign in: Use your Office 365 organization account to sign in during the setup process.
  • Configure the gateway: Register a new gateway, provide a unique name, and set a recovery key.

Installation Verification: In your power automate site, choose Gate way from the More option if it’s not available in the left menu

Picture13

The gateway is automatically visible there.

  • Now create a connection to the Gateway. Choose ‘Connections’ from the left menu and select New Connection.  Save the root folder, Authentication type, username, password of that system, etc.
Picture14
  • Use that connection in the flow action as per the requirements. e.g.
Picture15

2 Replies to “Handling Email Attachments with Power Automate: A Comprehensive Guide”

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts